﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.IoTManagement;
using Digitalmes.Model;



namespace Digitalmes.ViewModel.IoTManagement.MeterParameterVMs
{
    public partial class MeterParameterDeviceDetailListVM2 : BasePagedListVM<MeterParameter, MeterParameterDetailSearcher2>
    {
        
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
            };
        }
 
        protected override IEnumerable<IGridColumn<MeterParameter>> InitGridHeader()
        {
            return new List<GridColumn<MeterParameter>>{
                
                this.MakeGridHeader(x => x.ParamName).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.参数名称"].Value),
                this.MakeGridHeader(x => x.ParameterAddress).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.参数地址"].Value),
                this.MakeGridHeader(x => x.ParameterDataType).SetEditType(EditTypeEnum.ComboBox,typeof(TagDataTypeEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.数据类型"].Value),
                this.MakeGridHeader(x => x.ParamUnit).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.参数单位"].Value),
                this.MakeGridHeader(x => x.Description).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.参数说明"].Value),
                this.MakeGridHeader(x => x.Eanble).SetEditType(EditTypeEnum.ComboBox,Utils.GetBoolCombo(BoolComboTypes.YesNo, selectText:Wtm.Localizer?["Sys.PleaseSelect"])).SetTitle(@Localizer["Sys.Enable"].Value),

            };
        }

        
        public override IOrderedQueryable<MeterParameter> GetSearchQuery()
        {
                
            var id = (long?)Searcher.DeviceId.ConvertValue(typeof(long?));
            if (id == null)
                return new List<MeterParameter>().AsQueryable().OrderBy(x => x.ID);
            var query = DC.Set<MeterParameter>()
                .Where(x => id == x.DeviceId)

                .OrderBy(x => x.ID);
            return query;
        }

    }

    public partial class MeterParameterDetailSearcher2 : BaseSearcher
    {
        
        [Display(Name = "_Model._MeterParameter._Device")]
        public string DeviceId { get; set; }
    }

}

